package ar.uba.fi.taller2.cmmiassistant.frontend.reportes;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.LayoutManager;
import java.awt.Rectangle;

import javax.swing.JLabel;
import javax.swing.JPanel;

public class PanelAreaProcesoCellRenderer extends JPanel {

	private static final long serialVersionUID = -6937923967399191318L;

	protected static final int BORDE = 2;

	private JPanel panelInterno;
	private JLabel textoPanel;

	public PanelAreaProcesoCellRenderer() {
		initialize();
	}

	public PanelAreaProcesoCellRenderer(boolean isDoubleBuffered) {
		super(isDoubleBuffered);
		initialize();
	}

	public PanelAreaProcesoCellRenderer(LayoutManager layout) {
		super(layout);
		initialize();
	}

	public PanelAreaProcesoCellRenderer(LayoutManager layout,
			boolean isDoubleBuffered) {
		super(layout, isDoubleBuffered);
		initialize();
	}

	@SuppressWarnings("serial")
	protected JPanel getPanelInterno() {
		if (panelInterno == null) {
			panelInterno = new JPanel() {
				@Override
				public void paint(Graphics g) {
					super.paint(g);
					Graphics2D g2d = (Graphics2D) g;
					Color s1 = getForeground();
					Color e = Color.WHITE;
					Rectangle rect = getBounds();
					rect.setLocation(0, BORDE);
					rect.setSize(rect.width - BORDE, rect.height - BORDE*2);
					GradientPaint gradient = new GradientPaint(0, 0, s1, 0,
							rect.height / 2, e, true);
					g2d.setPaint(gradient);
					// g2d.drawRect(0,0,rect.width, rect.height);
					// Color s2 = Color.yellow;
					// Color e1 = Color.pink;
					// GradientPaint gradient1 = new GradientPaint(10, 10, s2,
					// 30,
					// 30, e1, true);
					// g2d.setPaint(gradient1);
					g2d.fillRect(rect.x, rect.y, rect.width, rect.height);
					// super.paint(g);
				}
			};
		}

		return panelInterno;
	}

	protected JLabel getTextoPanel() {
		if (textoPanel == null) {
			textoPanel = new JLabel("");
		}

		return textoPanel;
	}

	private void initialize() {
		setLayout(null);
		add(getTextoPanel());
		add(getPanelInterno());
	}

	public void setColorFondo(Color color) {
		getPanelInterno().setForeground(color);
	}

	public void setTexto(String texto) {
		getTextoPanel().setText(texto);
	}
}
